package main

import (
	"AttackTracer/StingHoneypot/RPC"
	"AttackTracer/StingHoneypot/config"
	"AttackTracer/StingHoneypot/utils/setting"
	"fmt"
	"os"
)

var (
	Conf          config.Config
	IncidentChann = make(chan RPC.Incident, 10)
)

func init() {
	// get config file path from command line
	var configPath string
	if len(os.Args) != 2 {
		fmt.Println("no config file provided")
		configPath = "/etc/AttackTracer/StingHoneypot.yaml"
	} else {
		configPath = os.Args[1]
	}
	fmt.Println("reading config from " + configPath)

	// parse config
	Conf, err := Conf.Parse(configPath)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if err = Conf.Validate(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	//log.Print(Conf)
}

func main() {

	fmt.Println("StingHoneypot starting")

	RPC.ConnectAnalyzer(Conf.RpcConf, IncidentChann) // connect to analyzer

	args := os.Args
	if args == nil || len(args) < 2 {
		setting.Help()
	} else {
		if args[1] == "help" || args[1] == "--help" {
			setting.Help()
		} else if args[1] == "init" || args[1] == "--init" {
			setting.Init()
		} else if args[1] == "version" || args[1] == "--version" {
			fmt.Println("v0.6.2")
		} else if args[1] == "run" || args[1] == "--run" {
			setting.Run()
		} else {
			setting.Help()
		}
	}
}
